package encryption;

import keygen.AESUtils;
import keygen.DESUtils;
import keygen.SHAUtil;
import keygen.TripleDESUtils;

/**
 * 加密算法测试
 * 在进行实际的开发过程中，一般是几种加密方式配合使用，
 * 这样加密效果会更好，被破解的概率会越小。
 */
public class Test {
    public static void main(String[] args) throws Exception {
//        //MD5加密
//        MD5Utils md5Utils = new MD5Utils();
//        String newStr = md5Utils.getMD5Code("123456");
//        System.out.println(newStr);
//
//        String newStrMD5 = md5Utils.getMD5Code("e10adc3949ba59abbe56e057f20f883e");
//        System.out.println(newStrMD5);
////        AESUtils.
//        String newStr2 = AESUtils.encrypt("li", "piao");
//        System.out.println(newStr2);
////        AESUtils.

        //MD5
        encryptionUtils encryptionUtils = new encryptionUtils();
        String str = "123456789";
        System.out.println("NewBeeMall新蜂商城 加密算法改进：使用混合加密");
        System.out.println("首先使用6种加密算法分别加密，查看加密效果 " + str);


        System.out.println();
        String newStrMd5 = encryptionUtils.getMD5Code(str);
        System.out.println("1.MD5加密 " + newStrMd5);

        System.out.println();
        //RSA
        String newStrRSA = encryptionUtils.getRSACode(str);
        System.out.println("2.RSA加密 " + newStrRSA);
        System.out.println("2.RSA解密 " + encryptionUtils.decipheringRSA(newStrRSA));

        System.out.println();
        //DES加密
        byte[] bytes = str.getBytes();
        byte[] bytesDESKey = DESUtils.initKey();
        System.out.println("3.DES密钥");
        for (byte b : bytesDESKey) {
            System.out.print(b + " ");
        }
        System.out.println();
        System.out.println("3.DES加密前，将字符串转化为byte数组输出");
        for (byte b : bytes) System.out.print(b + " ");
        byte[] newBytes = DESUtils.encrypt(bytes, bytesDESKey);
        System.out.println("  ");
        System.out.println("3.DES加密后");
        for (byte b : newBytes) System.out.print(b + " ");


        System.out.println();
        //AES
        byte[] bytes2 = str.getBytes();
        byte[] bytesAESKey = AESUtils.initKey();
        System.out.println("4.AES密钥");
        for (byte b : bytesAESKey) System.out.print(b + " ");
        System.out.println(" ");
        System.out.println("4.AES加密前，将字符串转化为byte数组输出");
        for (byte b : bytes2) System.out.print(b + " ");
        byte[] newBytes2 = DESUtils.encrypt(bytes, bytesDESKey);
        System.out.println();

        System.out.println("4.AES加密后");
        for (byte b : newBytes2) System.out.print(b + " ");


        System.out.println();
        //SHA
        byte[] bytes3 = str.getBytes();
        System.out.println("5.SHA加密");
        for (byte b : bytesAESKey) System.out.print(b + " ");
        System.out.println(" ");
        System.out.println("5.SHA加密前，将字符串转化为byte数组输出");
        for (byte b : bytes2) System.out.print(b + " ");
        String shastr = SHAUtil.encryptSHA(bytes3);
        System.out.println();
        System.out.println("5.SHA加密后");
        System.out.println(shastr);


        System.out.println();
        //3DES加密
        byte[] bytes4 = str.getBytes();
        byte[] bytesDESKey4 = TripleDESUtils.initKey();
        System.out.println("6.TripleDES密钥");
        for (byte b : bytesDESKey4) {
            System.out.print(b + " ");
        }
        System.out.println();
        System.out.println("6.TripleDES加密前，将字符串转化为byte数组输出");
        for (byte b : bytes4) System.out.print(b + " ");
        byte[] newBytes4 = TripleDESUtils.encrypt(bytes4, bytesDESKey4);
        System.out.println("  ");
        System.out.println("6.TripleDES加密后");
        for (byte b : newBytes4) System.out.print(b + " ");

        System.out.println();
        System.out.println("NewBeeMall新蜂商城 加密算法改进 使用混合加密");
        System.out.println("混合加密算法效果如下：同样以123456789为例");
        String newbeestr = "123456789";
        //两层MD5
        String newbeepasswordstr = encryptionUtils.getMD5Code(encryptionUtils.getMD5Code(newbeestr));
        byte[] newbeebytes = newbeepasswordstr.getBytes();
        //两层SHA
        byte[] newbeebytes2 = SHAUtil.encryptSHA(bytes3).getBytes();
        String newbeepasswordstr3 = SHAUtil.encryptSHA(newbeebytes2);
        System.out.println(newbeepasswordstr3);


    }
}
